/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 实例道具
	/// module : structs
	/// </summary>
	public class ItemPOD : IPOD 
    {
        public readonly static Func<ItemPOD> FACTORY = () => new ItemPOD();
		public static Func<ItemPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 唯一id
        /// </summary>
		public long id;
		/// <summary>
        /// item配置id
        /// </summary>
		public int cid;
		/// <summary>
        /// 已使用数量
        /// </summary>
		public int usedNum;
		/// <summary>
        /// 创建时间（毫秒时间戳）
        /// </summary>
		public long createTime;
		/// <summary>
        /// 过期时间(毫秒时间戳) 0代表永久	
        /// </summary>
		public long expireTime;
		/// <summary>
        /// 装备数据
        /// </summary>
		public ItemEquipmentPOD equipmentData;
		/// <summary>
        /// 手持道具数据
        /// </summary>
		public ItemPortablePOD portableData;
		
		
		
		/*-- constructors --*/
		public ItemPOD() {}
		public ItemPOD(long id, int cid, int usedNum, long createTime, long expireTime, ItemEquipmentPOD equipmentData, ItemPortablePOD portableData) {
			this.id = id;
			this.cid = cid;
			this.usedNum = usedNum;
			this.createTime = createTime;
			this.expireTime = expireTime;
			this.equipmentData = equipmentData;
			this.portableData = portableData;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_long(id);
            _out.Write_int(cid);
            _out.Write_int(usedNum);
            _out.Write_long(createTime);
            _out.Write_long(expireTime);
            _out.Write_pod(equipmentData);
            _out.Write_pod(portableData);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_long();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            usedNum = _in.Read_int();
            if(!_in.HasRemaining()) return;
            createTime = _in.Read_long();
            if(!_in.HasRemaining()) return;
            expireTime = _in.Read_long();
            if(!_in.HasRemaining()) return;
            equipmentData = _in.Read_pod<ItemEquipmentPOD>(ItemEquipmentPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            portableData = _in.Read_pod<ItemPortablePOD>(ItemPortablePOD.DynamicFactory);
        }
		
		public ItemPOD Clone() {
            ItemPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            o.usedNum = usedNum;
            o.createTime = createTime;
            o.expireTime = expireTime;
            if (equipmentData != null) {
                o.equipmentData = equipmentData.Clone();
            }
            if (portableData != null) {
                o.portableData = portableData.Clone();
            }
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            usedNum = default;
            createTime = default;
            expireTime = default;
            equipmentData = default;
            portableData = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "ItemPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", usedNum=";
			str += usedNum;
			str += ", createTime=";
			str += createTime;
			str += ", expireTime=";
			str += expireTime;
			str += ", equipmentData=";
			str += equipmentData;
			str += ", portableData=";
			str += portableData;
			str += "]";
			return str;
		}
		
	}
}